package com.google.code.p.restrpc.http;

import java.io.IOException;

import org.springframework.http.client.ClientHttpResponse;

public interface ResponseErrorHandler {
    
    /**
     * Indicates whether the given response has any errors. Implementations will
     * typically inspect the {@link ClientHttpResponse#getStatusCode()
     * HttpStatus} of the response.
     * 
     * @param response
     *            the response to inspect
     * @return <code>true</code> if the response has an error;
     *         <code>false</code> otherwise
     * @throws IOException
     *             in case of I/O errors
     */
    boolean hasError(HttpClientResponse response) throws IOException;
    
    /**
     * Handles the error in the given response. This method is only called when
     * {@link #hasError(ClientHttpResponse)} has returned <code>true</code>.
     * 
     * @param response
     *            the response with the error
     * @throws IOException
     *             in case of I/O errors
     */
    void handleError(HttpClientResponse response) throws IOException;
}
